package com.bwie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.pojo.TbShop;
import com.bwie.service.TbShopService;
import com.bwie.mapper.TbShopMapper;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author lenovo
 * @description 针对表【tb_shop】的数据库操作Service实现
 * @createDate 2025-06-26 09:32:06
 */
@Service
public class TbShopServiceImpl extends ServiceImpl<TbShopMapper, TbShop>
        implements TbShopService {

    @Autowired
    TbShopMapper tbShopMapper;

    @Override
    public R getShopList(PageInfoVo pageInfoVo) {


        Page<TbShop> page = new Page<>(pageInfoVo.getPageNum(), pageInfoVo.getPageSize());

        QueryWrapper<TbShop> wrapper = new QueryWrapper<>();

        wrapper.lambda().orderByDesc(TbShop::getSaleNum);

        if (StringUtils.isNotEmpty(pageInfoVo.getKeyWord())) {
            wrapper.lambda().like(TbShop::getShopName, pageInfoVo.getKeyWord());
        }
        if (pageInfoVo.getTypeId() != null) {
            wrapper.lambda().eq(TbShop::getBrandId, pageInfoVo.getTypeId());
        }
        Page<TbShop> tbShopPage = tbShopMapper.selectPage(page, wrapper);

        return R.OK(tbShopPage);
    }

    @Override
    public R addShop(TbShop tbShop) {

        tbShopMapper.insert(tbShop);

        return R.OK();
    }
}




